package cn.com.kh.batch;

import cn.com.elite.Util;
import cn.com.kh.*;
import cn.com.kh.result.iAPIResult;
import net.sf.json.JSONObject;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.jdbc.core.JdbcTemplate;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Title: cn.com.dev-DevTao
 * @Description:ngsapitask-ph 系统API接口开发Demo，重点关注业务逻辑部分
 * @Author: lijun
 * @Date 2021-12-03 10:23
 */
public class FCallAPI_Utils {
    private static final Log log = LogFactory.getLog(FCallAPI_Utils.class);
    private static String FDD_APIDomain = "https://qz.dbc61.com/api";
    private static String CC_APIDomain = "https://ronglian.dbc61.com/ngsapitask_ph/api";
    private static String APPID = "100002";
    private static String APPKEY = "E4uX9c65e5h7A5K5DA6rw6JL";
    private static String api_DBC_CustInfo = "";

    private static int i_Num = 0;

    // 获取-一体化-客户基础信息
    public static JSONObject getDBC_CustInfo(JdbcTemplate jt, String Rec_Guid, String customerId) {
        JSONObject res_Json = iAPIResult.ERROR("获取-海吉星客户基础信息 失败");
        Map<String, String> map = new HashMap<String, String>();
        try {
            map.put("customeroid", customerId);
            map.put("key", "ca3c64a49d1f11ecbed6d703198897725e7aba55");
            String postBody = KHUtil.ASCIIORDER(map);
            log.debug("获取-海吉星客户基础信息 参数:" + postBody);

            String customerUrl = KHUtil.isNull(api_DBC_CustInfo) ? KHDBConfig.getAPIURL(jt, "getCustomerinfo") : api_DBC_CustInfo;
            log.debug("获取-海吉星客户基础信息 地址：" + customerUrl);

            // 客户详细接口调用
            String res_DbcCust_Info = Util.doHttpPost(customerUrl, postBody, "UTF-8", 120000, 0);
            JSONObject res_DbcCust_Json = JSONObject.fromObject(res_DbcCust_Info);

            // 返回数据处理
            if (getProperty.get("FDDDev.Env").equals("1")) {
                String FDDDev_CustInfo = KHDBConfig.getParamConfig(jt, "FDDDev." + customerId);
                res_DbcCust_Json = KHUtil.isNull(FDDDev_CustInfo) ? iAPIResult.ERROR("模拟-海吉星客户基础信息 失败-未配置Code参数指定该用户信息") : JSONObject.fromObject(FDDDev_CustInfo);
            }
            log.debug("Ⓜ获取-海吉星客户基础信息 返回JSON：" + res_DbcCust_Json.toString());

            BatchData_Utils.toDBCCustInfoLog(jt, Rec_Guid, res_DbcCust_Json.getJSONObject("data"));

            res_Json = iAPIResult.SUCCESS("获取-海吉星客户基础信息 成功", res_DbcCust_Json);

        } catch (Exception e) {
            res_Json = iAPIResult.ERROR("获取-海吉星客户基础信息 异常:" + e.getMessage());
            log.error("⛔获取-海吉星客户基础信息 异常：" + e.getMessage(), e);

        } finally {
            BatchData_Utils.toSys_Oper_Log(jt, Rec_Guid, "获取海吉星用户信息", "调用海吉星一体化接口获取用户信息", "接口调用", "Rec_Guid:" + Rec_Guid + " customerId:" + customerId, "1", map.toString(), res_Json.toString());
        }
        return res_Json;
    }

    // 个人-获取-个人用户信息查询ByMobile
    public static JSONObject getFDDPersonInfo(JdbcTemplate jt, String Rec_Guid, String mobile) {

        JSONObject res_Json = iAPIResult.ERROR("获取-个人用户信息查询 失败");
        JSONObject jsonPara = new JSONObject();

        try {
            jsonPara.put("mobile", mobile);

            JSONObject jsons = FDDUtils.getCallBody(APPID, APPKEY, jsonPara.toString());

            String callResStr = HttpClientProxy.sendPost("https://ronglian.dbc61.com/ngsapitask_ph/api/apiFDDAPIProxy?callURL=" + (FDD_APIDomain + "/account/person/get"), jsons.toString(), "", 0);

            JSONObject callRes_Json = JSONObject.fromObject(callResStr);
            log.debug("Ⓜ获取-个人用户信息查询 结果JSON:" + callResStr);

            BatchData_Utils.toFDDCustInfoLog(jt, Rec_Guid, callRes_Json);

            res_Json = iAPIResult.SUCCESS("获取-个人用户信息查询 完成", callRes_Json);

        } catch (Exception e) {
            res_Json = iAPIResult.ERROR("获取-个人用户信息查询 异常:" + e.getMessage());
            log.error("⛔获取-个人用户信息查询 结果：" + res_Json, e);

        } finally {
            BatchData_Utils.toSys_Oper_Log(jt, Rec_Guid, "获取-个人用户信息查询", "调用法大大接口获取用户信息", "接口调用", "Rec_Guid:" + Rec_Guid + " mobile:" + mobile, "1", jsonPara.toString(), res_Json.toString());
        }

        return res_Json;

    }

    // 个人-推送-法大大个人注册
    public static JSONObject doFDDPersonRegi(JdbcTemplate jt, String Rec_Guid, String mobile) {

        JSONObject res_Json = iAPIResult.ERROR("推送-法大大个人注册 失败");
        JSONObject jsonPara = new JSONObject();

        try {

            jsonPara.put("type", 1);
            jsonPara.put("account", mobile);

            JSONObject jsons = FDDUtils.getCallBody(APPID, APPKEY, jsonPara.toString());

            String callResStr = HttpClientProxy.sendPost("https://ronglian.dbc61.com/ngsapitask_ph/api/apiFDDAPIProxy?callURL=" + (FDD_APIDomain + "/account/register"), jsons.toString(), "", 0);

            JSONObject callRes_Json = JSONObject.fromObject(callResStr);
            log.debug("Ⓜ推送-法大大个人注册 结果JSON:" + callResStr);

            res_Json = iAPIResult.SUCCESS("推送-法大大个人注册 完成", callRes_Json);

        } catch (Exception e) {
            res_Json = iAPIResult.ERROR("推送-法大大个人注册 异常:" + e.getMessage());
            log.error("⛔推送-法大大个人注册 结果：" + res_Json, e);

        } finally {
            BatchData_Utils.toSys_Oper_Log(jt, Rec_Guid, "法大大个人注册", "调用法大大个人注册", "接口调用", "Rec_Guid:" + Rec_Guid + " mobile:" + mobile, "1", jsonPara.toString(), res_Json.toString());
        }

        return res_Json;

    }

    // 个人-推送-法大大个人实名认证
    public static JSONObject doFDDPersonVerify(JdbcTemplate jt, String Rec_Guid, String Dbc_CustomerId, String Fdd_CustomerId, String mobile) {

        JSONObject res_Json = iAPIResult.ERROR("推送-法大大个人实名认证 失败");
        JSONObject jsonPara = new JSONObject();

        try {

            jsonPara.put("customerId", Fdd_CustomerId);
            jsonPara.put("mobile", mobile);
            jsonPara.put("verifiedWay", 9);
            jsonPara.put("pageModify", 1);
            jsonPara.put("isSendSms", 1);
            jsonPara.put("isRepeatVerified", 1);
            jsonPara.put("notifyUrl", CC_APIDomain + "/apiBatchSignMain?callbackType=" + KHUtil.encode("个人认证") + "&customerId=" + Dbc_CustomerId + "&recGuid=" + Rec_Guid);

            JSONObject jsons = FDDUtils.getCallBody(APPID, APPKEY, jsonPara.toString());

            String callResStr = HttpClientProxy.sendPost("https://ronglian.dbc61.com/ngsapitask_ph/api/apiFDDAPIProxy?callURL=" + (FDD_APIDomain + "/certification/person/url"), jsons.toString(), "", 0);

            JSONObject callRes_Json = JSONObject.fromObject(callResStr);
            log.debug("Ⓜ推送-法大大个人实名认证 结果JSON:" + callResStr);

            if (KHUtil.GetSFJV(callRes_Json, "code").equals("1002021")) {
                res_Json = doFDDPersonVerify(jt, Rec_Guid, Dbc_CustomerId, Fdd_CustomerId, mobile, 2);

            } else {

                res_Json = iAPIResult.SUCCESS("推送-法大大个人实名认证 完成", callRes_Json);

            }

        } catch (Exception e) {
            res_Json = iAPIResult.ERROR("推送-法大大个人实名认证 异常:" + e.getMessage());
            log.error("⛔推送-法大大个人实名认证 结果：" + res_Json, e);

        } finally {
            BatchData_Utils.toSys_Oper_Log(jt, Rec_Guid, "法大大个人实名认证", "调用法大大个人实名认证", "接口调用", "Rec_Guid:" + Rec_Guid + " Fdd_CustomerId:" + Fdd_CustomerId, "1", jsonPara.toString(), res_Json.toString());
        }

        return res_Json;

    }

    // 个人-推送-法大大个人实名认证(重新认证)
    public static JSONObject doFDDPersonVerify(JdbcTemplate jt, String Rec_Guid, String Dbc_CustomerId, String Fdd_CustomerId, String mobile, int isRepeatVerified) {

        JSONObject res_Json = iAPIResult.ERROR("推送-法大大个人实名重新认证 失败");
        JSONObject inJsonTwo = new JSONObject();

        try {
            inJsonTwo.put("customerId", Fdd_CustomerId);
            inJsonTwo.put("mobile", mobile);
            inJsonTwo.put("verifiedWay", 9);
            inJsonTwo.put("pageModify", 1);
            inJsonTwo.put("isSendSms", 1);
            inJsonTwo.put("isRepeatVerified", isRepeatVerified);
            inJsonTwo.put("notifyUrl", CC_APIDomain + "/apiBatchSignMain?callbackType=" + KHUtil.encode("个人认证") + "&customerId=" + Dbc_CustomerId + "&recGuid=" + Rec_Guid);

            JSONObject jsons = FDDUtils.getCallBody(APPID, APPKEY, inJsonTwo.toString());

            String callResStr = HttpClientProxy.sendPost("https://ronglian.dbc61.com/ngsapitask_ph/api/apiFDDAPIProxy?callURL=" + (FDD_APIDomain + "/certification/person/url"), jsons.toString(), "", 0);

            JSONObject callRes_Json = JSONObject.fromObject(callResStr);
            log.debug("Ⓜ推送-法大大个人实名重新认证 结果JSON:" + callResStr);

            res_Json = iAPIResult.SUCCESS("推送-法大大个人实名重新认证 完成", callRes_Json);

        } catch (Exception e) {
            res_Json = iAPIResult.ERROR("推送-法大大个人实名重新认证 异常:" + e.getMessage());
            log.error("⛔推送-法大大个人实名重新认证 结果：" + res_Json, e);

        } finally {
            BatchData_Utils.toSys_Oper_Log(jt, Rec_Guid, "法大大个人实名重新认证", "调用法大大个人实名重新认证", "接口调用", "Rec_Guid:" + Rec_Guid + " Fdd_CustomerId:" + Fdd_CustomerId, "1", inJsonTwo.toString(), res_Json.toString());
        }

        return res_Json;

    }

    // 企业-获取-企业信息查询
    public static JSONObject getFDDCompanyInfo(JdbcTemplate jt, String Rec_Guid, String companyName) {

        JSONObject res_Json = iAPIResult.ERROR("获取-企业用户信息查询 失败");
        JSONObject jsonPara = new JSONObject();

        try {
            jsonPara.put("companyName", companyName);

            JSONObject jsons = FDDUtils.getCallBody(APPID, APPKEY, jsonPara.toString());

            String callResStr = HttpClientProxy.sendPost("https://ronglian.dbc61.com/ngsapitask_ph/api/apiFDDAPIProxy?callURL=" + (FDD_APIDomain + "/company/user-info/list"), jsons.toString(), "", 0);

            JSONObject callRes_Json = JSONObject.fromObject(callResStr);
            log.debug("Ⓜ获取-企业用户信息查询 结果JSON:" + callResStr);

            BatchData_Utils.toFDDCompInfoLog(jt, Rec_Guid, callRes_Json);

            res_Json = iAPIResult.SUCCESS("获取-企业用户信息查询 完成", callRes_Json);

        } catch (Exception e) {
            res_Json = iAPIResult.ERROR("获取-企业用户信息查询 异常:" + e.getMessage());
            log.error("⛔获取-企业用户信息查询 结果：" + res_Json, e);

        } finally {
            BatchData_Utils.toSys_Oper_Log(jt, Rec_Guid, "获取-企业用户信息查询", "调用法大大接口获取企业用户信息", "接口调用", "Rec_Guid:" + Rec_Guid + " companyName:" + companyName, "1", jsonPara.toString(), res_Json.toString());
        }

        return res_Json;

    }

    // 企业-推送-法大大企业注册
    public static JSONObject doFDDCompanyRegi(JdbcTemplate jt, String Rec_Guid, String Fdd_CustomerId, String mobile, String companyName) {

        JSONObject res_Json = iAPIResult.ERROR("获取-企业用户信息查询 失败");
        JSONObject jsonPara = new JSONObject();

        try {

            jsonPara.put("type", 2);
            jsonPara.put("account", mobile);
            jsonPara.put("companyName", companyName);
            jsonPara.put("adminAccountId", Fdd_CustomerId);

            JSONObject jsons = FDDUtils.getCallBody(APPID, APPKEY, jsonPara.toString());

            String callResStr = HttpClientProxy.sendPost("https://ronglian.dbc61.com/ngsapitask_ph/api/apiFDDAPIProxy?callURL=" + (FDD_APIDomain + "/account/register"), jsons.toString(), "", 0);

            JSONObject callRes_Json = JSONObject.fromObject(callResStr);
            log.debug("Ⓜ推送-法大大企业注册 结果JSON:" + callResStr);

            res_Json = iAPIResult.SUCCESS("推送-法大大企业注册 完成", callRes_Json);

        } catch (Exception e) {
            res_Json = iAPIResult.ERROR("推送-法大大企业注册 异常:" + e.getMessage());
            log.error("⛔推送-法大大企业注册 结果：" + res_Json, e);

        } finally {
            BatchData_Utils.toSys_Oper_Log(jt, Rec_Guid, "推送-法大大企业注册", "调用法大大企业注册", "接口调用", "Rec_Guid:" + Rec_Guid + " Fdd_CustomerId:" + Fdd_CustomerId + " mobile:" + mobile + " companyName:" + companyName, "1", jsonPara.toString(), res_Json.toString());
        }

        return res_Json;

    }

    // 个人-推送-法大大企业实名认证
    public static JSONObject doFDDCompanyVerify(JdbcTemplate jt, String Rec_Guid, String Dbc_CustomerId, String Fdd_CompanyId, String mobile) {

        JSONObject res_Json = iAPIResult.ERROR("推送-法大大企业实名认证 失败");
        JSONObject jsonPara = new JSONObject();

        try {

            jsonPara.put("customerId", Fdd_CompanyId);
            jsonPara.put("verifiedWay", 0);
            jsonPara.put("pageModify", 1);
            jsonPara.put("isSendSms", 1);
            jsonPara.put("isRepeatVerified", 1); // 1-首次认证，2-重新认证
            jsonPara.put("companyPrincipalType", 2); // 1.法人，2代理人
            jsonPara.put("notifyUrl", CC_APIDomain + "/apiBatchSignMain?callbackType=" + KHUtil.encode("企业认证") + "&customerId=" + Dbc_CustomerId + "&recGuid=" + Rec_Guid);
            JSONObject AgentInfoDTO = new JSONObject();
            AgentInfoDTO.put("agentMobile", mobile);
            jsonPara.put("agentInfo", AgentInfoDTO);

            JSONObject jsons = FDDUtils.getCallBody(APPID, APPKEY, jsonPara.toString());

            String callResStr = HttpClientProxy.sendPost("https://ronglian.dbc61.com/ngsapitask_ph/api/apiFDDAPIProxy?callURL=" + (FDD_APIDomain + "/certification/company/url"), jsons.toString(), "", 0);

            JSONObject callRes_Json = JSONObject.fromObject(callResStr);
            log.debug("Ⓜ推送-法大大企业实名认证 结果JSON:" + callResStr);

            if (KHUtil.GetSFJV(callRes_Json, "code").equals("1002021")) {
                res_Json = doFDDCompanyVerify(jt, Rec_Guid, Dbc_CustomerId, Fdd_CompanyId, mobile, 2);

            } else {
                res_Json = iAPIResult.SUCCESS("推送-法大大企业实名认证 完成", callRes_Json);

            }

        } catch (Exception e) {
            res_Json = iAPIResult.ERROR("推送-法大大企业实名认证 异常:" + e.getMessage());
            log.error("⛔推送-法大大企业实名认证 结果：" + res_Json, e);

        } finally {
            BatchData_Utils.toSys_Oper_Log(jt, Rec_Guid, "法大大个人实名认证", "调用法大大个人实名认证", "接口调用", "Rec_Guid:" + Rec_Guid + " Fdd_CompanyId:" + Fdd_CompanyId + " mobile:" + mobile, "1", jsonPara.toString(), res_Json.toString());
        }

        return res_Json;

    }

    // 个人-推送-法大大企业实名认证(重新认证)
    public static JSONObject doFDDCompanyVerify(JdbcTemplate jt, String Rec_Guid, String Dbc_CustomerId, String Fdd_CompanyId, String mobile, int isRepeatVerified) {

        JSONObject res_Json = iAPIResult.ERROR("推送-法大大企业实名重新认证 失败");
        JSONObject jsonPara = new JSONObject();

        try {

            jsonPara.put("customerId", Fdd_CompanyId);
            jsonPara.put("verifiedWay", 0);
            jsonPara.put("pageModify", 1);
            jsonPara.put("isSendSms", 1);
            jsonPara.put("isRepeatVerified", isRepeatVerified); // 1-首次认证，2-重新认证
            jsonPara.put("companyPrincipalType", 2); // 1.法人，2代理人
            jsonPara.put("notifyUrl", CC_APIDomain + "/apiBatchSignMain?callbackType=企业认证&customerId=" + Dbc_CustomerId + "&recGuid=" + Rec_Guid);
            JSONObject AgentInfoDTO = new JSONObject();
            AgentInfoDTO.put("agentMobile", mobile);
            jsonPara.put("agentInfo", AgentInfoDTO);

            JSONObject jsons = FDDUtils.getCallBody(APPID, APPKEY, jsonPara.toString());

            String callResStr = HttpClientProxy.sendPost("https://ronglian.dbc61.com/ngsapitask_ph/api/apiFDDAPIProxy?callURL=" + (FDD_APIDomain + "/certification/company/url"), jsons.toString(), "", 0);

            JSONObject callRes_Json = JSONObject.fromObject(callResStr);
            log.debug("Ⓜ推送-法大大企业实名重新认证 结果JSON:" + callResStr);

            res_Json = iAPIResult.SUCCESS("推送-法大大企业实名重新认证 完成", callRes_Json);

        } catch (Exception e) {
            res_Json = iAPIResult.ERROR("推送-法大大企业实名重新认证 异常:" + e.getMessage());
            log.error("⛔推送-法大大企业实名重新认证 结果：" + res_Json, e);

        } finally {
            BatchData_Utils.toSys_Oper_Log(jt, Rec_Guid, "法大大个人实名重新认证", "调用法大大个人实名重新认证", "接口调用", "Rec_Guid:" + Rec_Guid + " Fdd_CompanyId:" + Fdd_CompanyId + " mobile:" + mobile, "1", jsonPara.toString(), res_Json.toString());
        }

        return res_Json;

    }

    // 获取-实名认证状态查询(个人&公司)
    public static JSONObject getCertificationStatus(JdbcTemplate jt, String Rec_Guid, String get_Type, String customerId) {

        JSONObject res_Json = iAPIResult.ERROR(get_Type + "实名认证状态查询 失败");
        JSONObject jsonPara = new JSONObject();

        try {
            jsonPara.put("customerId", customerId);

            JSONObject jsons = FDDUtils.getCallBody(APPID, APPKEY, jsonPara.toString());

            String callResStr = HttpClientProxy.sendPost("https://ronglian.dbc61.com/ngsapitask_ph/api/apiFDDAPIProxy?callURL=" + (FDD_APIDomain + (get_Type.equals("公司") ? "/certification/company/get-status" : "/certification/person/get-status")), jsons.toString(), "", 0);
            JSONObject callRes_Json = JSONObject.fromObject(callResStr);
            log.debug("Ⓜ获取-实名认证状态查询(个人&公司) " + get_Type + "实名认证状态查询 结果JSON:" + callResStr);

            res_Json = iAPIResult.SUCCESS(get_Type + "实名认证状态查询 完成", callRes_Json);

        } catch (Exception e) {
            res_Json = iAPIResult.ERROR(get_Type + "实名认证状态查询 异常:" + e.getMessage());
            log.error("⛔获取-实名认证状态查询(个人&公司) " + get_Type + "实名认证状态查询异常 结果：" + res_Json, e);

        } finally {
            BatchData_Utils.toSys_Oper_Log(jt, Rec_Guid, "获取海吉星用户信息", "调用海吉星一体化接口获取用户信息", "接口调用", "Rec_Guid:" + Rec_Guid + " get_Type:" + get_Type + " customerId:" + customerId, "1", jsonPara.toString(), res_Json.toString());
        }

        return res_Json;

    }

    // 获取-查询合同签署状态详情
    public static JSONObject getContractSignStatus(JdbcTemplate jt, String Rec_Guid, String ContractNo) {

        JSONObject res_Json = iAPIResult.ERROR("获取-查询合同签署状态详情 失败");
        JSONObject jsonPara = new JSONObject();

        try {

            jsonPara.put("docNo", ContractNo);

            JSONObject jsons = FDDUtils.getCallBody(APPID, APPKEY, jsonPara.toString());

            String callResStr = HttpClientProxy.sendPost("https://ronglian.dbc61.com/ngsapitask_ph/api/apiFDDAPIProxy?callURL=" + (FDD_APIDomain + "/sign/detail"), jsons.toString(), "", 0);
            JSONObject callRes_Json = JSONObject.fromObject(callResStr);
            log.debug("Ⓜ获取-查询合同签署状态详情 结果:" + callResStr);

            BatchData_Utils.toFDDSignLog(jt, Rec_Guid, callRes_Json);

            res_Json = iAPIResult.SUCCESS("获取-查询合同签署状态详情 完成", callRes_Json);

        } catch (Exception e) {
            res_Json = iAPIResult.ERROR("获取-查询合同签署状态详情 异常:" + e.getMessage());
            log.error("⛔获取-查询合同签署状态详情 异常：" + e.getMessage(), e);

        } finally {
            BatchData_Utils.toSys_Oper_Log(jt, Rec_Guid, "获取法大大查询合同签署状态", "调用法大大接口查询合同签署状态详情", "接口调用", "Rec_Guid:" + Rec_Guid + " ContractNo:" + ContractNo, "1", jsonPara.toString(), res_Json.toString());
        }

        return res_Json;

    }

    // 个人-获取-根据用户查询合同
    public static JSONObject doFDDContractSearch(JdbcTemplate jt, String Rec_Guid, String customerId) {

        JSONObject res_Json = iAPIResult.ERROR("获取-根据用户查询合同 失败");
        JSONObject jsonPara = new JSONObject();

        try {
            jsonPara.put("personCustomerId", customerId);

            JSONObject jsons = FDDUtils.getCallBody(APPID, APPKEY, jsonPara.toString());

            String callResStr = HttpClientProxy.sendPost("https://ronglian.dbc61.com/ngsapitask_ph/api/apiFDDAPIProxy?callURL=" + (FDD_APIDomain + "/contract/search"), jsons.toString(), "", 0);
            JSONObject callRes_Json = JSONObject.fromObject(callResStr);
            log.debug("Ⓜ获取-根据用户查询合同 结果JSON:" + callResStr);

            res_Json = iAPIResult.SUCCESS("获取-根据用户查询合同 完成", callRes_Json);

        } catch (Exception e) {
            res_Json = iAPIResult.ERROR("获取-根据用户查询合同 异常:" + e.getMessage());
            log.error("⛔获取-根据用户查询合同 结果：" + res_Json, e);

        } finally {
            BatchData_Utils.toSys_Oper_Log(jt, Rec_Guid, "获取-根据用户查询合同", "调用法大大接口获取根据用户查询合同", "接口调用", "Rec_Guid:" + Rec_Guid + " customerId:" + customerId, "1", jsonPara.toString(), res_Json.toString());
        }

        return res_Json;

    }

    // 获取-法大大合同模板控件
    public static JSONObject getFDDTemplateFields(JdbcTemplate jt, String Rec_Guid, String Modelid) {
        JSONObject res_Json = iAPIResult.ERROR("获取-获取合同模板控件 失败");
        JSONObject jsonPara = new JSONObject();
        try {
            HashMap<String, Object> headMap = new HashMap<>();
            headMap.put("Content-Type", "application/json");

            jsonPara.put("id", Modelid);

            JSONObject jsons = FDDUtils.getCallBody(APPID, APPKEY, jsonPara.toString());

            String callResStr = Util.doHttpPostUseHead(FDD_APIDomain + "/online-template/widget/list", jsons.toString().replace("\\n", ""), "UTF-8", 12000, 0, headMap);

            JSONObject callRes_Json = JSONObject.fromObject(callResStr);
            log.debug("Ⓜ获取-法大大合同模板控件 结果JSON:" + callRes_Json);

            res_Json = iAPIResult.SUCCESS("获取-法大大合同模板控件 完成", callRes_Json);

        } catch (Exception e) {
            res_Json = iAPIResult.ERROR("获取-查询合同签署状态详情 异常:" + e.getMessage());
            log.error("⛔获取-法大大合同模板控件 异常：" + e.getMessage(), e);

        } finally {
            BatchData_Utils.toSys_Oper_Log(jt, Rec_Guid, "获取-法大大合同模板控件", "调用法大大-获取-法大大合同模板控件", "接口调用", "Rec_Guid:" + Rec_Guid + " Modelid:" + Modelid, "1", jsonPara.toString(), res_Json.toString());
        }
        return res_Json;
    }

    // 通过生成合同(模版)Main
    public static JSONObject doFDDContractCreate(JdbcTemplate jt, String Rec_Guid, List assList, String templateId, String propertyNumber, String companyCustomerid, String contractId) {
        JSONObject res_Json = iAPIResult.ERROR("推送-通过模版生成合同Main 失败");
        JSONObject jsonPara = new JSONObject();
        try {
            HashMap<String, Object> headMap = new HashMap<>();
            headMap.put("Content-Type", "application/json");

            jsonPara.put("id", templateId);
            jsonPara.put("contractTitle", propertyNumber);
            jsonPara.put("contractNo", contractId);
            jsonPara.put("personCustomerId", "");
            jsonPara.put("companyCustomerId", companyCustomerid);//personCustomerId
            jsonPara.put("onlineWidgetDetailDTOS", assList);
            jsonPara.put("crossPlatform", 1);//因法大大改版新增

            JSONObject jsons = FDDUtils.getCallBody(APPID, APPKEY, jsonPara.toString());

            String callRes_Info = Util.doHttpPostUseHead(FDD_APIDomain + "/online-template/fill", jsons.toString().replace("\\n", ""), "UTF-8", 120000, 0, headMap);
            log.debug("Ⓜ推送-通过模版生成合同Main 返回结果:" + callRes_Info);

            JSONObject callRes_Json = JSONObject.fromObject(callRes_Info);

            if (KHUtil.GetSFJV(callRes_Json, "code").equals("1")) {

                int i_Num = jt.update("Update Ph_Contract_Sign_List Set Contract_Id = ? Where Rec_Guid = ?", contractId, Rec_Guid);
                log.debug("推送-通过模版生成合同Main 合同生成返回,更新合同编号 i_Num:" + i_Num);

                res_Json = iAPIResult.SUCCESS("获取-查询合同签署状态详情 完成", callRes_Json);

            } else {
                res_Json = iAPIResult.ERROR("推送-通过模版生成合同Main 返回错误:" + KHUtil.GetSFJV(callRes_Json, "msg"));
            }

        } catch (Exception e) {
            res_Json = iAPIResult.ERROR("获取-查询合同签署状态详情 异常:" + e.getMessage());
            log.error("⛔获取-查询合同签署状态详情 异常：" + e.getMessage(), e);

        } finally {
            BatchData_Utils.toSys_Oper_Log(jt, Rec_Guid, "获取法大大查询合同签署状态", "调用法大大接口查询合同签署状态详情", "接口调用", "Rec_Guid:" + Rec_Guid, "1", jsonPara.toString(), res_Json.toString());
        }
        return res_Json;
    }

    // 推送-合同撤销
    public static JSONObject doFDDContractRevoke(JdbcTemplate jt, String Rec_Guid, String docNo) {

        JSONObject res_Json = iAPIResult.ERROR("推送-合同撤销 失败");
        JSONObject jsonPara = new JSONObject();

        try {

            jsonPara.put("docNo", docNo);

            JSONObject jsons = FDDUtils.getCallBody(APPID, APPKEY, jsonPara.toString());

            String callResStr = HttpClientProxy.sendPost("https://ronglian.dbc61.com/ngsapitask_ph/api/apiFDDAPIProxy?callURL=" + (FDD_APIDomain + "/contract/revoke"), jsons.toString(), "", 0);

            JSONObject callRes_Json = JSONObject.fromObject(callResStr);
            log.debug("Ⓜ推送-合同撤销 结果JSON:" + callResStr);

            res_Json = iAPIResult.SUCCESS("推送-合同撤销 完成", callRes_Json);

        } catch (Exception e) {
            res_Json = iAPIResult.ERROR("推送-合同撤销 异常:" + e.getMessage());
            log.error("⛔推送-合同撤销 结果：" + res_Json, e);

        } finally {
            BatchData_Utils.toSys_Oper_Log(jt, Rec_Guid, "合同撤销", "调用合同撤销", "接口调用", "Rec_Guid:" + Rec_Guid + " docNo:" + docNo, "1", jsonPara.toString(), res_Json.toString());
        }

        return res_Json;

    }

    // 3-1-推送乙方签署
    public static JSONObject pushPartyBSign(JdbcTemplate jt, String rec_Guid, Map<String, Object> signBMap) {
        JSONObject res_Json = new JSONObject();
        log.debug("3-1-推送乙方签署 待签署乙方信息:" + signBMap.toString());

        HashMap<String, Object> headMap = new HashMap<>();
        headMap.put("Content-Type", "application/json");
        try {
            String fddCustomerId = KHUtil.GetMapV(signBMap, "Customerid");
            String contractId = KHUtil.GetMapV(signBMap, "Contractid");
            String fddGroup_id = KHUtil.GetMapV(signBMap, "Fddgroup_Id");
            String customerType = KHUtil.GetMapV(signBMap, "Customertype");
            String transactionNo = KHUtil.GetMapV(signBMap, "Agreementduid");
            int orderNum = Integer.parseInt(KHUtil.GetMapV(signBMap, "Ordernum"));

            JSONObject jsonPara = new JSONObject();
            if (customerType.equals("2")) {
                jsonPara.put("companyCustomerId", fddCustomerId);
                //平台交易号--用于签署回调唯一标识
                jsonPara.put("docNo", contractId);
                jsonPara.put("autoArchive", "2");
                jsonPara.put("transactionNo", transactionNo);
                jsonPara.put("notifyUrl", CC_APIDomain + "/apiBatchSignMain?callbackType=" + KHUtil.encode("乙方签署回调") + "&customerType=" + customerType + "&recGuid=" + rec_Guid + "&agreementDuid=" + transactionNo);

                //第一个关键字，公司盖章
                Map<String, Object> CompanySealKeywordDTO1 = new HashMap<String, Object>();
                CompanySealKeywordDTO1.put("companyKeyWord", KHDBConfig.getParam(jt, "YFQYGZ")); //关键字
                CompanySealKeywordDTO1.put("companyKeywordStrategy", 0);
                CompanySealKeywordDTO1.put("companyKeywordOffsetX", 30);
                CompanySealKeywordDTO1.put("companyKeywordOffsetY", 50 * orderNum);
                CompanySealKeywordDTO1.put("sealName", KHDBConfig.getParam(jt, "GONGZ")); //印章名称

                //第二个关键字，法人签名
                Map<String, Object> CompanySealKeywordDTO2 = new HashMap<String, Object>();
                CompanySealKeywordDTO2.put("companyKeyWord", KHDBConfig.getParam(jt, "YFQYQM")); //关键字
                CompanySealKeywordDTO2.put("companyKeywordStrategy", 0);
                CompanySealKeywordDTO2.put("companyKeywordOffsetX", 30);
                CompanySealKeywordDTO2.put("companyKeywordOffsetY", 50 * orderNum);
                CompanySealKeywordDTO2.put("sealName", KHDBConfig.getParam(jt, "FANRZ")); //印章名称

                //将关键字拼接成list
                List<Map<String, Object>> companySealInfoslist = new ArrayList<>();
                companySealInfoslist.add(CompanySealKeywordDTO1);
                companySealInfoslist.add(CompanySealKeywordDTO2);
                jsonPara.put("companySealInfos", companySealInfoslist);

                if (fddGroup_id.equals("VBFWBF")) { //如果合同模板类型是解除合同，则推送时间章关键字
                    //签署时间：传时间章关键字
                    JSONObject jsondatePara = new JSONObject();
                    jsondatePara.put("keyword", KHDBConfig.getParam(jt, "YFHTQS")); //时间章关键字
                    jsondatePara.put("keywordStrategy", 0);
                    jsondatePara.put("keywordOffsetX", 30);
                    jsondatePara.put("keywordOffsetY", 50 * orderNum);
                    jsonPara.put("dateSealKeywordDTO", jsondatePara);
                }
            } else {
                jsonPara.put("customerId", fddCustomerId);
                //平台交易号--用于签署回调唯一标识
                jsonPara.put("docNo", contractId);
                jsonPara.put("autoArchive", "2");
                jsonPara.put("transactionNo", transactionNo);
                jsonPara.put("isSendSms", 1);

                jsonPara.put("notifyUrl", CC_APIDomain + "/apiBatchSignMain?batchId=202407230002&callbackType=" + KHUtil.encode("乙方签署回调") + "&customerType=" + customerType + "&customerId=" + fddCustomerId + "&recGuid=" + rec_Guid + "&transactionNo=" + transactionNo + "&agreementDuid=" + transactionNo);
                //关键字设置
                jsonPara.put("personKeyWord", KHDBConfig.getParam(jt, "YFQMC")); //关键字
                jsonPara.put("personKeywordStrategy", 0);
                jsonPara.put("personKeywordOffsetX", 30);
                jsonPara.put("personKeywordOffsetY", 50 * orderNum);
                if (fddGroup_id.equals("VBFWBF")) { //如果合同模板类型是解除合同，则推送时间章关键字
                    //签署时间：传时间章关键字
                    JSONObject jsondatePara = new JSONObject();
                    jsondatePara.put("keyword", KHDBConfig.getParam(jt, "YFHTQS")); //时间章关键字
                    jsondatePara.put("keywordStrategy", 0);
                    jsondatePara.put("keywordOffsetX", 30);
                    jsondatePara.put("keywordOffsetY", 50 * orderNum);
                    jsonPara.put("dateSealKeywordDTO", jsondatePara);
                }
            }

            JSONObject jsons = FDDUtils.getCallBody(APPID, APPKEY, jsonPara.toString());

            String res_PushSignInfo = "";
            if (customerType.equals("2")) {
                //调用法大大推送签署接口，文档编号HT103
                res_PushSignInfo = Util.doHttpPostUseHead(FDD_APIDomain + "/sign/portal-url/push/customized", jsons.toString().replace("\\n", ""), "UTF-8", 120000, 0, headMap);
            } else {
                //调用法大大推送签署接口，文档编号HT103
                res_PushSignInfo = Util.doHttpPostUseHead(FDD_APIDomain + "/sign/portal-url/push", jsons.toString().replace("\\n", ""), "UTF-8", 120000, 0, headMap);
            }
            log.debug("Ⓜ推送乙方签署接口返回：" + res_PushSignInfo);
            JSONObject res_PushSignJson = JSONObject.fromObject(res_PushSignInfo);

            // 判断是否推送签署成功,记录签署结果
            String res_Code = KHUtil.GetSFJV(res_PushSignJson, "code");
            String res_Msg = KHUtil.GetSFJV(res_PushSignJson, "msg");
            if (res_Code.equals("1")) {
                i_Num = jt.update("Update Fdd_Agreement_List Set Pushsigning = '已推送', Transactionno = ?, Pushsigningtime = Now() Where Agreementduid = ?", transactionNo, transactionNo);
                log.debug("推送乙方签署成功,记录签署结果 DB:" + i_Num);

                res_Json = iAPIResult.SUCCESS("推送乙方签署成功", transactionNo);
            } else {

                i_Num = jt.update("Update Fdd_Agreement_List Set Pushsigning = '推送失败', Pushfailreason = ?, Transactionno = ?, Pushsigningtime = Now(), pushFailTime = Now() Where Agreementduid = ?", res_Msg + "(" + res_Code + ")", transactionNo, transactionNo);
                log.debug("推送乙方签署失败,记录签署结果 DB:" + i_Num);

                res_Json = iAPIResult.ERROR("推送乙方签署失败", res_PushSignJson);
            }

        } catch (Exception e) {
            res_Json = iAPIResult.ERROR("推送乙方签署 异常(" + e.getMessage() + ")");
            log.error("⛔推送乙方签署 异常(" + e.getMessage() + ")", e);
        }

        log.debug("3-1-推送乙方签署 待签署乙方推送End 结果:" + res_Json.toString());
        return res_Json;
    }

    // 3-2-推送甲方签署
    public static JSONObject pushPartyASign(JdbcTemplate jt, String rec_Guid, Map<String, Object> signMap, String autoArchive) {
        JSONObject res_Json = new JSONObject();
        log.debug("3-2-推送甲方签署 待签署甲方信息:" + signMap.toString() + " autoArchive:" + autoArchive);

        HashMap<String, Object> headMap = new HashMap<>();
        headMap.put("Content-Type", "application/json");

        //结果标识
        try {

            String fddCustomerId = KHUtil.GetMapV(signMap, "Customerid");
            String contractId = KHUtil.GetMapV(signMap, "Contractid");
            String transactionNo = KHUtil.GetMapV(signMap, "Agreementduid");
            String htType = KHUtil.GetMapV(signMap, "Ht_Type");

            //查询推送甲方类型对应法大大个人编号、企业编号、签字位置、时间位置
            List<Map<String, Object>> signInfoList = jt.queryForList("Select Customerid, Companycustomerid, Seal_Location, Date_Location From Fdd_Admin Where Customerid = ? And Fdd_Type = ? Order By Ordernum Asc", fddCustomerId, htType);

            //企业签署时：个人客户编号不传，则默认推送给企业管理员代表企业签署；个人客户编号有传，则该个人代表企业签署
            Map<String, Object> signInfoMap = signInfoList.get(0);
            String fdd_CustomerId = KHUtil.GetMapV(signInfoMap, "Customerid");
            String fdd_CompanyCustomerId = KHUtil.GetMapV(signInfoMap, "Companycustomerid");
            String sealLocation = KHUtil.GetMapV(signInfoMap, "Seal_Location"); // 甲方盖章处
            String dateLocation = KHUtil.GetMapV(signInfoMap, "Date_Location"); // 甲方签章日期

            //平台交易号--用于签署回调唯一标识
            JSONObject jsonPara = new JSONObject();
            jsonPara.put("customerId", fdd_CustomerId);
            jsonPara.put("companyCustomerId", fdd_CompanyCustomerId);
            jsonPara.put("docNo", contractId);
            jsonPara.put("autoArchive", autoArchive);
            jsonPara.put("transactionNo", transactionNo);
            jsonPara.put("isSendSms", 1);
            jsonPara.put("notifyUrl", CC_APIDomain + "/apiBatchSignMain?callbackType=" + KHUtil.encode("甲方签署回调") + "&customerType=" + htType + "&recGuid=" + rec_Guid + "&agreementDuid=" + transactionNo);
            jsonPara.put("companyKeyWord", sealLocation);
            jsonPara.put("companyKeywordStrategy", 0);

            JSONObject jsondatePara = new JSONObject();
            jsondatePara.put("keyword", dateLocation);
            jsondatePara.put("keywordStrategy", 0);
            jsonPara.put("dateSealKeywordDTO", jsondatePara);

            JSONObject jsons = FDDUtils.getCallBody(APPID, APPKEY, jsonPara.toString());

            String res_PushSignInfo = "";
            if (getProperty.get("FDDDev.Env").equals("1")) {
                res_PushSignInfo = "{\"code\":1,\"msg\":\"开发环境-不推送法大大甲方签署,默认返回推送成功\"}";
            } else {
                res_PushSignInfo = Util.doHttpPostUseHead(FDD_APIDomain + "/sign/portal-url/push", jsons.toString().replace("\\n", ""), "UTF-8", 120000, 0, headMap);
            }
            JSONObject res_PushSignJson = JSONObject.fromObject(res_PushSignInfo);
            log.debug("Ⓜ推送甲方门户签署返回:" + res_PushSignJson.toString());

            // 判断是否推送签署成功,记录签署结果
            String res_Code = KHUtil.GetSFJV(res_PushSignJson, "code");
            String res_Msg = KHUtil.GetSFJV(res_PushSignJson, "msg");
            if (res_Code.equals("1")) {
                i_Num = jt.update("Update Fdd_Agreement_List Set Pushsigning = '已推送', Transactionno = ?, Pushsigningtime = Now() Where Agreementduid = ?", transactionNo, transactionNo);
                log.debug("推送甲方签署成功,记录签署结果 DB:" + i_Num);

                res_Json = iAPIResult.SUCCESS("推送甲方签署成功", transactionNo);
            } else {

                i_Num = jt.update("Update Fdd_Agreement_List Set Pushsigning = '推送失败', Pushfailreason = ?, Transactionno = ?, Pushsigningtime = Now(), pushFailTime = Now() Where Agreementduid = ?", res_Msg + "(" + res_Code + ")", transactionNo, transactionNo);
                log.debug("推送甲方签署失败,记录签署结果 DB:" + i_Num);

                res_Json = iAPIResult.ERROR("推送甲方签署失败", res_PushSignJson);
            }

        } catch (Exception e) {
            res_Json = iAPIResult.ERROR("推送甲方签署 异常(" + e.getMessage() + ")");
            log.error("⛔推送甲方签署 异常(" + e.getMessage() + ")", e);
        }

        log.debug("3-1-推送甲方签署 待签署甲方推送End 结果:" + res_Json.toString());
        return res_Json;
    }

}